package com.richinfo.buddy.common.utils;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * 注：需在src/main/resources下的META-INF/spring.factories配置
 * 
* Created by WangXJ
* 2019-05-16 15:11
 */
public class BuddySpringApplicationRunListener implements SpringApplicationRunListener {

    private static ConfigurableApplicationContext applicationContext;

    public BuddySpringApplicationRunListener(SpringApplication application, String[] args) {
    }

    @Override
    public void starting() {
    }

    @Override
    public void environmentPrepared(ConfigurableEnvironment environment) {
    }

    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
        BuddySpringApplicationRunListener.applicationContext = context;
    }

    public void finished(ConfigurableApplicationContext context, Throwable exception) {
    }

    public static ConfigurableApplicationContext getApplicationContext() {
        return applicationContext;
    }

	@Override
	public void started(ConfigurableApplicationContext context) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void running(ConfigurableApplicationContext context) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void failed(ConfigurableApplicationContext context, Throwable exception) {
		// TODO Auto-generated method stub
		
	}
}